package servlet;

import java.io.IOException;

import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.BookService;
import service.ReaderSerivice;
import vo.BookBean;
import vo.ReaderBean;

public class BookReaderJson extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	// TODO Auto-generated method stub
	resp.setContentType("application/json,charset=utf-8");

	int rid=Integer.parseInt(req.getParameter("rid"));
	int bid=Integer.parseInt(req.getParameter("bid"));
	String data=null;
	ReaderSerivice rs=new ReaderSerivice();
	if(rs.get(rid).size()>0){
		List<Object> list = rs.get(rid);
		ReaderBean rb=(ReaderBean) list.get(0);
		BookService bs=new BookService();
		List<Object> book = bs.get(bid);
		BookBean bb=(BookBean) book.get(0);
		System.out.println(rb.getR_money());
		System.out.println(bb.getB_price());
		if(rb.getR_money()>bb.getB_price()){
			data="{\"state\":\"2\"}";
		}else{
			data="{\"state\":\"1\"}";
		}
		
	}else{
		
		data="{\"state\":\"0\"}";
		
	}
	resp.getWriter().write(data);
}
@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
	doGet(req, resp);
	}
}
